package com.zzy.controller;

import com.zzy.model.AjaxMsg;
import com.zzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


@RestController
@RequestMapping(value = "/")
@EnableEurekaClient
public class UserController {


    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private  UserService userService;


    /** 通过 eureka 调用  */
    @GetMapping("get/users")
    public String users() {
        return restTemplate.getForObject("http://ZZY-PROVIDER/users", String.class);
    }

    /** 通过 eureka 调用  */
    @GetMapping("get/test")
    public String test() {
        return restTemplate.getForObject("http://ZZY-PROVIDER/index/test", String.class);
    }



    /** 通过 FeignClient 调用  http://localhost:8085/get/1  */
    @GetMapping("get/{id}")
    public AjaxMsg FeignClient(@PathVariable Integer id) {
        return AjaxMsg.returnAjaxMsg(userService.getuserinfo(id));//
    }




}
